package com.zlcx.tz.live.repository;

import com.zlcx.tz.live.domain.TimeLearnRoomDO;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Lock;
import org.springframework.stereotype.Repository;
import javax.persistence.LockModeType;
import java.util.List;

/**
 * @author anjl
 */
@Repository
public interface TimeLearnRoomRepository extends JpaRepository<TimeLearnRoomDO, Long>, JpaSpecificationExecutor<TimeLearnRoomDO> {

    /**
     * 更新房间内人数时，使用此方法，对数据行进行加锁，防止出现脏读
     * @param roomId roomId
     */
    @Lock(value = LockModeType.PESSIMISTIC_WRITE)
    TimeLearnRoomDO findById(Long roomId);

    List<TimeLearnRoomDO> findByType(Integer type);
}
